#ifndef _KC_UNICODECODER_H__KC_
#define _KC_UNICODECODER_H__KC_

#include <stdexcept>
#include <unicode/unistr.h>
#include <boost/utility.hpp>

namespace kc_sf
{
	struct UnicodeConverterError : std::logic_error
	{
		UnicodeConverterError(const std::string &msg)
		: std::logic_error(msg)
		{
		}
	};

	// NIE THREAD-SAFE!
	/* Przeksztalca napisy o stronie kodowej codepage w unicode 16
	 */
	class UnicodeConverter : boost::noncopyable // throws UnicodeConverterError
	{
		public:

			UnicodeConverter();
			explicit UnicodeConverter(const std::string &codepage);
			~UnicodeConverter();

			bool encode (const std::string &input, UnicodeString &output) const;
			bool decode (const UnicodeString &input, std::string &output) const;

			UnicodeString encode (const std::string &input) const;
			std::string decode (const UnicodeString &input) const;

		private:

			std::string u_codepage;
			UConverter *u_converter; // converts from codepage to utf-16 and back

			void CreateConverter();
			void InitConverter();
	};
}

#endif // _KC_UNICODECODER_H__KC_
